package com.fanfan.controller;

import com.baomidou.mybatisplus.extension.api.R;
import com.fanfan.pojo.Role;
import com.fanfan.pojo.User;
import com.fanfan.pojo.domain.ResponseResult;
import com.fanfan.pojo.vo.RoleDto;
import com.fanfan.service.RoleService;
import com.fanfan.utils.BeanCopyUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.parameters.P;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("system/role")
public class RoleController {
    @Autowired
    RoleService roleService;
    @GetMapping("/list")
    public ResponseResult listRole(Integer pageNum, Integer pageSize, Role role){
       return roleService.listRole(pageNum,pageSize,role);
    }
    @PutMapping("/changeStatus")
    public ResponseResult reviseRole(@RequestBody Role role){
        roleService.getBaseMapper().updateById(role);
        return ResponseResult.okResult();
    }
    @PostMapping
    public ResponseResult addRole(@RequestBody RoleDto roleDto){
        roleService.addRole(roleDto);
        return ResponseResult.okResult();
    }
    @GetMapping("/{id}")
    public ResponseResult showRole(@PathVariable Long id){
        return roleService.showRole(id);
    }
    @PutMapping
    public ResponseResult updateRole(@RequestBody RoleDto roleDto){
        return roleService.updateRole(roleDto);
    }
    @DeleteMapping("/{id}")
    public ResponseResult deleteRole(@PathVariable Long id){
        roleService.getBaseMapper().deleteById(id);
        return ResponseResult.okResult();
    }
    @GetMapping("/listAllRole")
    public ResponseResult listAllRole(){
        List<Role> roles = roleService.getBaseMapper().selectList(null);
        return ResponseResult.okResult(roles);
    }
}












